package com.hzo.great.leisuregreat.utils;

import org.xutils.common.Callback;
import org.xutils.ex.HttpException;

import java.net.ConnectException;
import java.net.SocketTimeoutException;


/**
 * Created by Administrator on 2016/9/19.
 */
public class MyStringCallback<T> implements Callback.CommonCallback<String> {

    @Override
    public void onSuccess(String result) {

    }

    @Override
    public void onError(Throwable ex, boolean isOnCallback) {
        LogUtils.e(ex.toString());
        if (ex instanceof ConnectException) {//网络连接失败
            LogUtils.e("服务器连接失败");
        } else if (ex instanceof HttpException) { // 网络错误
            LogUtils.e("网络错误");
            HttpException httpEx = (HttpException) ex;
            int responseCode = httpEx.getCode();
            String responseMsg = httpEx.getMessage();
            String errorResult = httpEx.getResult();
            // ...
        } else if (ex instanceof SocketTimeoutException) {
            LogUtils.e("服务器连接超时");
        } else {
            // 其他错误
        }
    }

    @Override
    public void onCancelled(CancelledException cex) {

    }

    @Override
    public void onFinished() {
    }
}
